package com.veo.dao;

import com.veo.domain.Permission;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionsDao {

    //根据id查权限
    @Select("select * from permission where id in (select permissionId from role_permission where roleId=#{roleId})")
    List<Permission> findPermissionById(String roleId);

    //查询所有权限
    //@Select("select * from permission")
    @Select("<script>" + "select * from permission "+"<where>"+
            "<if test=\"searcherName!= null and searcherName!=''\"> permissionName like concat(#{searcherName},'%')</if>"+
            "</where>"+
            "</script>")
    List<Permission> findAllPermission(@Param("searcherName") String searcherName);

    //添加权限
    @Insert("insert into permission(id,permissionName,url) values(#{id},#{permissionName},#{url})")
    int addPermission(Permission permission);

    //删除权限
    @Delete("delete from role_permission where permissionId=#{id}")
    int deleteRolePermissionId(String id);
    @Delete("delete from permission where id=#{id}")
    int deletePermissionById(String id);
}
